package com.lz.common.utils.file;

/**
 * @author caicai
 * @date 2021/8/27 14:08
 */
public enum AudioContentType {
    /**
     * 非法类型
     */
    ILLEGAL("", "", 0),
    MP3("audio/mpeg", "MP3", 1),
    WAV("audio/wave", "WAV", 2);

    private String contentType;
    private String type;
    private int code;

    AudioContentType(String contentType, String type, int code) {
        this.contentType = contentType;
        this.type = type;
        this.code = code;
    }

    public static AudioContentType create(String contentType) {
//        if (StringUtils.isNullOrEmpty(contentType)) {
        if (contentType == null || contentType.isEmpty()) {
            return ILLEGAL;
        }
        for (AudioContentType type : values()) {
            if (type.contentType.equals(contentType)) {
                return type;
            }
        }
        return ILLEGAL;
    }

    public static AudioContentType create(int code) {
        for (AudioContentType type : values()) {
            if (type.code == code) {
                return type;
            }
        }
        return ILLEGAL;
    }

    public static AudioContentType create(Integer code) {
        return create(code.intValue());
    }

    public String getContentType() {
        return contentType;
    }

    public int getCode() {
        return code;
    }

    public String getType() {
        return type;
    }
}